import gtk
import time

class View(gtk.Window):
    '''
    Primary User-Interface
    '''
    
    def __init__(self, model):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_title("Recordmanager")
        self.set_size_request(900,400)
        
        # Attributes
        self.__model = model
        self.__btnBoxLeft = gtk.VButtonBox()
        self.__btnBoxLeft.set_layout(gtk.BUTTONBOX_SPREAD)
        self.__btnBoxLeftInLeft = gtk.HButtonBox()
        self.__btnBoxLeftInRight = gtk.HButtonBox()
        #self.__btnBoxLeftInLeft.set_homogeneous(True)   #warum funktionierts nicht?
        #self.__btnBoxLeftInRight.set_homogeneous(True)
        
        self.__btnCreateProject = gtk.Button("Projekt anlegen")
        self.__btnCreateProject.set_size_request(130,25)
        self.__btnBurn = gtk.Button("Brennen")
        self.__btnBurn.set_size_request(130,25)
        self.__btnPack = gtk.Button("Komprimieren")
        self.__btnPack.set_size_request(130,25)
        self.__btnUnpack = gtk.Button("De-Komprimieren")
        self.__btnUnpack.set_size_request(130,25)
        self.__btnRecord = gtk.Button("Aufnahme")
        self.__btnRecord.set_size_request(130,25)
        self.__btnOk = gtk.Button("OK")
        self.__btnOk.set_size_request(130,25)
        
        # Fill ButtonBox
        self.__btnBoxLeft.add(self.__btnBoxLeftInLeft)
        self.__btnBoxLeft.add(self.__btnBoxLeftInRight)
        self.__btnBoxLeftInLeft.add(self.__btnCreateProject)
        self.__btnBoxLeftInLeft.add(self.__btnBurn)
        self.__btnBoxLeftInRight.add(self.__btnPack)
        self.__btnBoxLeftInRight.add(self.__btnUnpack)
        
        # Left side
        left = gtk.VBox()
        left.pack_start(gtk.Label("Projects"))
        left.pack_start(self.__model.getProjectList())
        left.pack_start(self.__btnBoxLeft)
        
        # Right side
        rtable = gtk.Table(3,2)
        rtable.attach(gtk.Label("Date:"), 0, 1, 0, 1)
        rtable.attach(gtk.Label("Preacher:"), 0, 1, 1, 2)
        rtable.attach(gtk.Label("Topic:"), 0, 1, 2, 3)
        tfDate = gtk.Entry()
        tfDate.set_text(time.strftime("%d.%m.%Y"))
        rtable.attach(tfDate, 1, 2, 0, 1)
        tfPreacher = gtk.Entry();
        rtable.attach(tfPreacher, 1, 2, 1, 2)
        tfTopic = gtk.Entry();
        rtable.attach(tfTopic, 1, 2, 2, 3)
        
        self.__btnBoxRight = gtk.HButtonBox()
        self.__btnBoxRight.add(self.__btnOk)
        right = gtk.VBox()        
        
        right.set_property("width-request", 200)
        right.set_property("height-request", 200)
        right.pack_start(rtable)
        right.pack_start(self.__btnBoxRight)
        
        
        #test
        test = gtk.Window
        #test.set_has_frame(True)
        
        
        
        hpaned = gtk.HPaned()
        hpaned.pack1(left, shrink=False)
        #hpaned.pack2(test)
        self.add(hpaned)
        
        self.__model.load_sermons()
        self.show_all()
        self.show()
        self.connect("destroy", self._quit)
        
    def _quit(self, *args):
        gtk.main_quit()
